package com.tdxy.pm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class IndexPanel extends JPanel {
    // 窗体
    JFrame frame ;
    // 文本框
    JTextField userField ;
    JPasswordField pwdField ;
    // 按钮
    JButton loginButton ;

    public IndexPanel(JFrame frame) {
        // 画板布局方式为 无布局
        setLayout(null);
        this.frame = frame ;
        // 将 变量初始化
        userField = new JTextField();
        pwdField = new JPasswordField();
        loginButton = new JButton();
        // 进行组件的布局
        userField.setBounds(360,180,120,30);
        pwdField.setBounds(360,280,120,30);
        loginButton.setBounds(300,400,100,40);
        // Button 内容的填写
        loginButton.setText("登陆");
        // Button 的监听

        loginButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                CardLayout layout = (CardLayout) frame.getContentPane().getLayout() ;
                layout.show(frame.getContentPane(),"panel");

                // 获取输入框的文本值
//                String userStr = userField.getText();
//                String pwdStr = pwdField.getText();
//                System.out.println("点击了登陆按钮"+ userStr + pwdStr);
            }
        });
        // 画板添加组件
        this.add(userField);
        this.add(pwdField);
        this.add(loginButton);
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.setColor(Color.BLACK);
        g.fillRect(0,0,800,600);
        g.setColor(Color.WHITE);
        g.setFont(new Font("微软雅黑", Font.BOLD , 30));
        g.drawString("图书管理系统",300,100);

        g.setFont(new Font("微软雅黑", Font.BOLD , 20));
        g.drawString("请输入用户名",200,200);

        g.setFont(new Font("微软雅黑", Font.BOLD , 20));
        g.drawString("请输入密码",200,300);

        userField.repaint();
        pwdField.repaint();
        loginButton.repaint();
    }
}
